app.controller('GetTopdataCtrl',function ($scope,$http,$localStorage,$location,$window,$state) {
	$scope.namedata = $localStorage.cur_user.uname;
	console.log($state.params);
	var layerdata = $state.params.layerdata.split(',');
	var dd,ll,hh,ww,nn;
	$scope.layerdata = [];
	$scope.layerdata[0] = layerdata[0];
	if(layerdata[1]!=""){
		 dd = layerdata[1].split('+')[0];
		 ll = layerdata[1].split('+')[1];
		 $scope.layerdata[1] = dd;
	}
	if(layerdata[2]!=""){
		$scope.layerdata[2] = layerdata[2]
	}
	
	if(layerdata[3]!=""){
		hh = layerdata[3].split('+')[0];
		ww = layerdata[3].split('+')[1];
		nn = layerdata[3].split('+')[2];
		$scope.layerdata[3] = hh
	}

	var keydata = $state.params.key;
	var keys = {};
	$scope.keys = {};
	if(keydata!=''){
		if(keydata=="power"){
			keys.power = "实时功率"
		}
		if(keydata=="current"){
			keys.current = "实时电流"		
		}
		if(keydata=="voltage"){
			keys.voltage = "实时电压"
		}
		if(keydata=="total_power"){
			keys.total_power = "总电量"
		}
		$scope.keys = keys;
	}else{
		$scope.keys.param = "参数没有选择"
	}

	$scope.currentPage = 1;//初始当前页
    $scope.maxSize = 3;//最多显示3页其他的用···代替
    $http.post(
        $scope.app.backendurl+"tbl-electricity/top",
        {    
            'page':$scope.currentPage,  
            'school_name':layerdata[0],
            'school_id':ll,
            'key':$state.params.key,	               	
            'campus_building_id':ww,
            'building_name':layerdata[2],
            'building_type':dd,
            'layer_id':nn,
            'layer_name':hh,
            'token':$localStorage.token                  

        }
      ).success(function (data) {
        console.log(data);
        if(data.code==0&&data.msg=="读取成功"){             
          $scope.aaData = data.data.models;
          $scope.totalItems = data.data.page.totalCount;          
        }
        if(data.code==20001&&data.msg=='请先登录'){
          $location.path('access.signin');
        }
        if(data.code==1){
        	alert(data.msg)
        }  

    $scope.pageChanged = function(){
    	console.log($scope.currentPage)
    	 $http.post(
            $scope.app.backendurl+"tbl-electricity/top",
            {    
                'page':$scope.currentPage,  
	            'school_name':layerdata[0],
	            'school_id':ll,
	            'key':$state.params.key,	               	
	            'campus_building_id':ww,
	            'building_name':layerdata[2],
	            'building_type':dd,
	            'layer_id':nn,
	            'layer_name':hh,
	            'token':$localStorage.token            
   

            }
          ).success(function (data) {
          	console.log(data);
          	if(data.code==0&&data.msg=="读取成功"){             
              $scope.aaData = data.data.models;	                    
            }
            if(data.code==1){
            	alert(data.msg)
            }
            if(data.code==20001&&data.msg=='请先登录'){
              $location.path('access.signin');
            }  
          }).error(function(data){

    	 })
    }    
    }).error(function(data){
      console.log(data);
    })
	


	

})